package com.skycode6.servlet;

import com.skycode6.bean.NewsBean;
import com.skycode6.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/adminUser.jsp")
public class AdminUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // 3
        String p = req.getParameter("page");
        int page = 1;
        if (p != null && p.equals("")){//页面字符串不为空 强制转化为数字
            page = Integer.parseInt(p);
        }
        // 3
        NewsDao newsDao = new NewsDao();
        List<NewsBean> news = newsDao.getList(page);
        req.setAttribute("news",news);
        // 4显示页面 网页重定向显示
        req.getRequestDispatcher("WEB-INF/news.jsp").forward(req,resp);
    }
}

